class RingBuffer:
    def __init__(self, size_max):
        self.max = size_max + 1
        self.data = [None] * self.max
        self.wrPos = 0
        self.rdPos = 0

    def is_ringbuffer_full(self):
        if (self.wrPos + 1) % self.max == self.rdPos:
            return 1
        else:
            return 0

    def is_ringbuffer_empty(self):
        if self.wrPos == self.rdPos:
            return 1
        else:
            return 0

    # pop up data from rb
    def get(self):
        if self.is_ringbuffer_empty():
            return None
        ret = self.data[self.rdPos]
        self.rdPos = (self.rdPos + 1) % self.max
        return ret

    # push data to rb
    def append(self, item):
        if self.is_ringbuffer_full():
            return 0
        self.data[self.wrPos] = item
        self.wrPos = (self.wrPos + 1) % self.max
        return 1
